const express = require("express");
const newsList = require("./data")
const app = express();
app.get("/",(req,res)=>{
	// "<p>令人唏嘘！张纪中前妻愤怒控诉：3亿财产转移、隐私泄露 拒绝道歉</p><p>白玉兰视后票选爆冷，杨紫缘何大幅领先？"
	res.send(newsList.map(item=>(`
		<p><a href="/detail/${item.id}.html">${item.title}</a></p>
	`)).join(""))
})
// http://zhangpeiyue.com/detail/K1JP0NS10553TKJG.html
app.get("/detail/:id.html",(req,res)=>{
	const {id} = req.params;
	const info = newsList.find(item=>item.id === id);
	if(info){
		res.send(`
			<div>
				<a href="/">返回首页</a>
				<hr/>
				<h3>${info.title}</h3>
				<p>${info.content}</p>
				<img src="${info.img}" alt="">
			</div>
		`);
	}else{
		res.send("新闻不存在！");
	}

})
app.listen(80,()=>{
	console.log("success");
})